package com.rupertjones.globalcron.web;

import com.rupertjones.globalcron.web.model.DisplayableJob;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.HandlesEvent;
import net.sourceforge.stripes.action.Resolution;

import java.util.Collection;

/**
 * <p>&copy Rupert Jones 2011,2012</p>
 *
 * @author rup
 */
public class HomeAction extends AbstractAction {

    public Collection<DisplayableJob> getEnabledJobs() {
        return getJobService().getEnabledJobs();
    }

    public Collection<DisplayableJob> getDisabledJobs() {
        return getJobService().getDisabledJobsForHost();
    }

    public Collection<DisplayableJob> getExecutingJobs() {
        return getJobService().getExecutingJobs();
    }

    @HandlesEvent("StopAll")
    public Resolution stopAll() {
        getJobService().stopAll();
        return view();
    }

    @DefaultHandler
    public Resolution view() {
        return new ForwardResolution("/WEB-INF/jsp/home.jsp");
    }
}
